﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using SocialPlatformSDK.Model;

namespace SocialPlatformSDK
{

    public interface ISocialFactory
    {
        void SaveData(AccessToken token);
    }
    /// <typeparam name="T">子类类型</typeparam>
    /// <typeparam name="M">子类实体类类型</typeparam>
    public abstract class SocialFactoryBase<T> : ISocialFactory
        where T:new ()
    {
        /// <summary>
        /// 为提高效率，目前采用单例
        /// </summary>
        public static readonly T Instance = new T();

        protected SocialFactoryBase()
        {
        }

        public virtual void Validate()
        {

        }


        public virtual void ClearAccessToken()
        {

        }

        public virtual void SaveData(AccessToken token)
        {

        }
        /// <summary>
        /// 发布完成后回调委托
        /// </summary>
        /// <param name="message"></param>
        /// <returns></returns>
        public delegate void SocialShareHandler(bool isSuccess, string message);

        /// <summary>
        /// 微博分享
        /// </summary>
        /// <param name="channelName"></param>
        /// <param name="channelUrl"></param>
        public virtual void SocialShare(string channelName, string channelUrl, SocialShareHandler callBack)
        {
            SocialSharePublish(channelName, channelUrl, FormateMessage(channelName, channelUrl), callBack);
        }

        /// <summary>
        /// 格式化微博内容
        /// </summary>
        /// <param name="channelName"></param>
        /// <param name="channelUrl"></param>
        /// <returns></returns>
        private string FormateMessage(string channelName, string channelUrl)
        {
            return string.Format("我正在#PPTV WindowsPhone 客户端#观看#{0}#{1}", channelName, channelUrl);
        }

        /// <summary>
        /// 发布
        /// </summary>
        /// <param name="channelName"></param>
        /// <param name="channelUrl"></param>
        /// <param name="message"></param>
        public abstract void SocialSharePublish(string channelName,
            string channelUrl, string message, SocialShareHandler callBack);
    }
}
